<?php

$opts = array(
    'http' => array(
        'method' => "GET",
        'timeout' => 10,
    )
);
$context = stream_context_create($opts);

error_reporting(0);
$localIp = file_get_contents('http://imail.sinaapp.com/ip.php', false, $context);
if (!$localIp) {
    $localIp = file_get_contents('http://imail.sinaapp.com/ip.php', false, $context);
}
$arrReportResult = array();
$arrReportResult['ip'] = $localIp;

$arrReportResult['mysqld_count'] = intval(shell_exec('ps -ef | grep mysql | wc -l'));
$arrReportResult['httpd_count'] = intval(shell_exec('ps -ef | grep httpd | wc -l'));
$arrReportResult['uptime'] = shell_exec('uptime');
$arrReportResult['logsize'] = shell_exec('du -h /data/logs/ | tail -1');
$mysqlps = preg_replace('#\s+#', '', shell_exec('ps -ef | grep mysql'));
$pmysql = '#--datadir=(.*)-#iU';
preg_match_all($pmysql, $mysqlps, $psmysql);
$mysql_data_dir = $psmysql[1][0];
$arrReportResult['mysqlsize'] = shell_exec('du -h ' . $mysql_data_dir . ' | tail -1');

$arrReportResult['site_count'] = intval(shell_exec('ls /data/webroot/www/ | wc -l'));
$arrReportResult['sitelist'] = shell_exec('ls /data/webroot/www/');
if(!$arrReportResult['site_count']){
	$arrReportResult['site_count'] = $arrReportResult['site_count'] + intval(shell_exec('ls /home/web/webroot/www/ | wc -l'));
}

$arrReportResult['free-m'] = shell_exec('free -m | head -2');
$arrReportResult['df-h'] = shell_exec('df -h /data/');
$arrReportResult['ps-ef'] = shell_exec('ps -ef');

$arrReportResult['mysqlconn'] = '<font color="green">OK</font>';
$dbconn = mysql_connect('127.0.0.1', 'root', 'china@888') or $arrReportResult['mysqlconn'] = '<font color="red">ERROR</font>';

if ($_GET['isprint']) {
    echo '<pre>';
    print_r($arrReportResult);
    die();
}

echo json_encode($arrReportResult);
?>